<template>
    <div class="register">
        <div class="top">
            <div class="title">{{ detailStroe.hospitalInfo.hospital?.hosname }}</div>
            <div class="level">
                <svg t="1698852003705" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
                    p-id="4046" width="16" height="16">
                    <path
                        d="M857.28 344.992h-264.832c12.576-44.256 18.944-83.584 18.944-118.208 0-78.56-71.808-153.792-140.544-143.808-60.608 8.8-89.536 59.904-89.536 125.536v59.296c0 76.064-58.208 140.928-132.224 148.064l-117.728-0.192A67.36 67.36 0 0 0 64 483.04V872c0 37.216 30.144 67.36 67.36 67.36h652.192a102.72 102.72 0 0 0 100.928-83.584l73.728-388.96a102.72 102.72 0 0 0-100.928-121.824zM128 872V483.04c0-1.856 1.504-3.36 3.36-3.36H208v395.68H131.36A3.36 3.36 0 0 1 128 872z m767.328-417.088l-73.728 388.96a38.72 38.72 0 0 1-38.048 31.488H272V476.864a213.312 213.312 0 0 0 173.312-209.088V208.512c0-37.568 12.064-58.912 34.72-62.176 27.04-3.936 67.36 38.336 67.36 80.48 0 37.312-9.504 84-28.864 139.712a32 32 0 0 0 30.24 42.496h308.512a38.72 38.72 0 0 1 38.048 45.888z"
                        p-id="4047"></path>
                </svg>
                <span>{{ detailStroe.hospitalInfo.hospital?.param.hostypeString }}</span>
            </div>
        </div>
        <!-- 内容展示区 -->
        <div class="content">
            <div class="left">
                <img v-if="detailStroe.hospitalInfo.hospital"
                    :src="'data:image/jpeg;base64,' + detailStroe.hospitalInfo.hospital.logoData" alt="logo">
            </div>
            <div class="right">
                <div>挂号规则</div>
                <div class="time">
                    预约周期:{{ detailStroe.hospitalInfo.bookingRule?.cycle }}天
                    放号时间:{{ detailStroe.hospitalInfo.bookingRule?.releaseTime }}
                    停挂时间:{{ detailStroe.hospitalInfo.bookingRule?.stopTime }}
                </div>
                <div class="address">
                    具体位置:{{ detailStroe.hospitalInfo.hospital?.param.fullAddress }}
                </div>
                <div class="router">
                    具体路线:{{ detailStroe.hospitalInfo.hospital?.route }}
                </div>
                <div class="releaseTime">
                    退号时间:就诊前一工作日{{ detailStroe.hospitalInfo.bookingRule?.quitTime }}前取消
                </div>
                <div class="rule">预约挂号规则</div>
                <div class="ruleInfo" v-for="(rule, index) in detailStroe.hospitalInfo.bookingRule?.rule" :key="index">
                    {{ `${index + 1}. ${rule}` }}
                </div>
            </div>
        </div>
        <!-- 科室展示区 -->
        <div class="footer">
            <div class="leftNav">
                <ul>
                    <li @click="changeIndex(index)" :class="{ active: index === currentIndex }"
                        v-for="(department, index) in detailStroe.departmentInfo" :key="department.depcode">
                        {{ department.depname }}
                    </li>
                </ul>
            </div>
            <div class="departmentInfo">
                <!-- 代表大科室与小科室 -->
                <div class="showDepartment" v-for="department in detailStroe.departmentInfo" :key="department.depcode">
                    <h1 class="cur">{{ department.depname }}</h1>
                    <!-- 大科室下的小科室 -->
                    <ul>
                        <li v-for="item in department.children" :key="item.depcode">
                            <span @click="showLogin(item)">{{ item.depname }}</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
defineOptions({
    name: "Register"
})

// 导入组合式 api 
import { ref } from 'vue';
// 引入医院详情数据
import useDetailStore from '@/store/modules/hospitalDetail';
// 引入路由器
import { useRouter, useRoute } from "vue-router"


// 创建医院详情数据
let detailStroe = useDetailStore();
// 控制科室高亮的响应式数据
let currentIndex = ref<number>(0);
// 创建一个路由器实例
const router = useRouter();
// 创建一个路由实例
const route = useRoute();


// 点击左侧列表的函数
const changeIndex = (index: number) => {
    // 将 class 标识符变为被点击的 index 
    currentIndex.value = index;
    //点击导航获取右侧大科室的 h1 标题
    let allH1 = document.getElementsByClassName("cur");
    // 默认滚动到父元素的顶部
    allH1[index].scrollIntoView({
        // 采取平滑的动画过渡
        behavior: 'smooth'
    });
}
// 点击科室回调
const showLogin = (item: any) => {
    // 点击某一个科室的按钮，进入到对应的预约挂号详情页面
    // 携带 query 参数：医院编号和科室编号
    router.push({ path: "/hospital/register_step1", query: { hoscode: route.query.hoscode, depcode: item.depcode } })
    // 显示登录组件
    // userStore.visiable = true;
}
</script>

<style scoped lang="scss">
.register {
    display: flex;
    flex-direction: column;

    .top {
        display: flex;

        .title {
            font-size: 20px;
            font-weight: bold;
        }

        .level {
            display: flex;
            color: #7f7f7f;
            margin-left: 10px;
            padding-top: 3px;

            span {
                margin-left: 5px;
            }
        }
    }

    .content {
        display: flex;
        margin-top: 20px;

        .left {
            width: 80px;

            img {
                width: 80px;
                height: 80px;
                // 圆角
                border-radius: 50%;
            }
        }

        .right {
            // 除图片外剩余的部分
            flex: 1;
            padding-top: 20px;
            padding-left: 10px;
            font-size: 14px;

            .time,
            .address,
            .router,
            .releaseTime,
            .ruleInfo {
                margin-top: 10px;
                color: #7f7f7f;
            }

            .rule {
                margin: 10px 0;
            }
        }
    }

    .footer {
        width: 100%;
        height: 500px;
        margin-top: 30px;
        display: flex;

        .leftNav {
            width: 80px;

            ul {
                width: 100%;
                height: 100%;
                background-color: rgb(248, 248, 248);
                // 开启弹性盒，主轴设为纵向
                display: flex;
                flex-direction: column;

                li {
                    // 箭头
                    cursor: default;
                    // 每个元素占相等的高度
                    flex: 1;
                    // 文字水平居中
                    text-align: center;
                    color: #7f7f7f;
                    font-size: 14px;
                    // 想要文字垂直居中需要设置行高为所占 li 的高度，设置 align-items: center 无效
                    line-height: 41px;

                    &.active {
                        border-left: 1px solid red;
                        color: red;
                        background-color: white;
                    }
                }
            }
        }

        .departmentInfo {
            // 铺满剩余右侧区域
            flex: 1;
            margin-left: 20px;
            // 内容溢出时提供滚动条
            overflow: auto;

            // 隐藏滚动条
            &::-webkit-scrollbar {
                display: none;
            }

            .showDepartment {
                h1 {
                    background-color: rgb(248, 248, 248);
                    color: #7f7f7f;
                    line-height: 30px;
                    font-size: small;
                    padding-left: 5px;
                }

                ul {
                    display: flex;
                    flex-wrap: wrap;
                    margin-left: 10px;

                    li {
                        width: 33%;
                        color: #7f7f7f;
                        line-height: 30px;
                        margin: 5px 0;

                        span {
                            cursor: pointer;
                        }
                    }
                }
            }
        }
    }
}
</style>